<template>
  <div class="image-properties">
    <el-form label-position="top">
      <el-form-item label="图片地址">
        <el-input
          v-model="properties.src"
          placeholder="请输入图片地址"
          @change="updateProperties" />
      </el-form-item>
      
      <el-form-item label="填充方式">
        <el-select
          v-model="properties.fit"
          placeholder="请选择填充方式"
          @change="updateProperties">
          <el-option label="填充" value="fill" />
          <el-option label="包含" value="contain" />
          <el-option label="覆盖" value="cover" />
          <el-option label="无" value="none" />
          <el-option label="缩放" value="scale-down" />
        </el-select>
      </el-form-item>
      
      <el-form-item label="宽度">
        <el-input-number
          v-model="properties.width"
          :min="0"
          @change="updateProperties" />
      </el-form-item>
      
      <el-form-item label="高度">
        <el-input-number
          v-model="properties.height"
          :min="0"
          @change="updateProperties" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'

const props = defineProps({
  value: {
    type: Object,
    default: () => ({
      src: '',
      fit: 'cover',
      width: '100%',
      height: 'auto'
    })
  }
})

const emit = defineEmits(['update'])

const properties = ref({ ...props.value })

watch(() => props.value, (newVal) => {
  properties.value = { ...newVal }
}, { deep: true })

const updateProperties = () => {
  emit('update', { ...properties.value })
}
</script> 